package com.ruoyi.business.controller.app;

import com.ruoyi.business.service.IWsdSuggestionsService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.dto.WsdSuggestionsDTO;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.entity.WsdSuggestions;
import com.ruoyi.common.core.domain.vo.WsdSuggestionsVO;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 用于记录投诉和建议的信息   小程序
 *
 * @author ruoyi
 * @date 2024-04-19
 */
@RestController
@RequestMapping("wx_suggestions")
public class WxAppWsdSuggestionsController extends BaseController
{
    @Autowired
    private IWsdSuggestionsService wsdSuggestionsService;

    /**
     * 新增记录投诉和建议的信息
     */
    @Log(title = "用于记录投诉和建议的信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WsdSuggestionsDTO wsdSuggestionsDTO) {
        SysUser user = getLoginUser().getUser();
        Long schoolId = user.getSchoolId();
        wsdSuggestionsDTO.setSchoolId(schoolId);
        Long userId = user.getUserId();
        wsdSuggestionsDTO.setSubmitterId(userId);
        wsdSuggestionsDTO.setContactInfo(user.getPhonenumber());
        wsdSuggestionsDTO.setName(user.getNickName());
        wsdSuggestionsDTO.setDateTime(new Date());
        return toAjax(wsdSuggestionsService.insertWsdSuggestions(wsdSuggestionsDTO));
    }

    /**
     * 查询用于记录投诉和建议的信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WsdSuggestions wsdSuggestions) {
        startPage();
        List<WsdSuggestions> list = wsdSuggestionsService.selectWsdSuggestionsList(wsdSuggestions);
        return getDataTable(list);
    }

    /**
     * 获取用于记录投诉和建议的信息详细信息
     */
    @GetMapping(value = "/{suggestionsId}")
    public AjaxResult getInfo(@PathVariable("suggestionsId") Long suggestionsId) {
        return success(wsdSuggestionsService.selectWsdSuggestionsBySuggestionsId(suggestionsId));
    }
}
